home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / xmasspak / vector / vector10.asm next >
Encoding:
Assembly Source File  |  1996-05-21  |  25.3 KB  |  1,198 lines

  1.  ;
  2. ;  Line-Vector-routine v2.2
  3. ;
  4. ;  done 1995 by Capella/Escape
  5. ;  this routine is only for Escape-usage .... DON'T SPREAD!!!!
  6. ;
  7.  
  8. ideal
  9. model large
  10. p386n
  11. stack 256
  12.  
  13. assume cs:coding
  14.  
  15. points = 6                ; Anzahl Punkte
  16. areas = 6               ; Anzahl Linien
  17. frames = 2              ; Anzahl Flächen 
  18. ;-------------------------------------
  19. macro  setcol   backcol
  20.  
  21.        mov dx,03c8h
  22.        xor al,al
  23.        out dx,al
  24.        inc dx
  25.        mov al,backcol
  26.        out dx,al
  27.        out dx,al
  28.        out dx,al
  29.  
  30. endm
  31. ;-------------------------------
  32. macro  setpage newpage
  33.  
  34.        mov dx,03d4h
  35.        mov ax,newpage
  36.        out dx,ax
  37.  
  38. endm
  39. ;-------------------------------
  40.  
  41. segment  coding
  42.  
  43. start:     mov ax,data1
  44.            mov ds,ax
  45.            assume ds:data1
  46.  
  47.            mov ax,0a000h
  48.            mov es,ax
  49.            assume es:0a000h
  50.  
  51.            call set320400
  52.           ;  call set640400
  53.  
  54.            mov ax,0a800h
  55.            mov es,ax
  56.            assume es:0a800h
  57.  
  58.  
  59. main:      call  rotate_x       
  60.            call  rotate_y
  61.            call  rotate_z
  62.  
  63.            call transform
  64.            
  65.            mov [ds:color],1         ; Objekt auf Seite 2 darstellen
  66.            mov di,offset _2dpoints
  67.          ;  call draw_obj
  68.            
  69.            call sort_frames
  70.  
  71.            call fill_obj
  72.            
  73.            
  74.  
  75.            setpage 800ch           ; Seite 2 an
  76.            
  77.            mov dx,03dah
  78. wb1:       in al,dx
  79.            test al,8
  80.            jne wb1
  81. wb2:       in al,dx
  82.            test al,8
  83.            je wb2
  84.  
  85.            mov ax,0a000h
  86.            mov es,ax
  87.            assume es:0a000h
  88.            
  89.            mov dx,03c4h
  90.            mov ax,0f02h
  91.            out dx,ax
  92.  
  93.            mov cx,32000/4        ; Objekt auf Seite 1 löschen
  94.            xor si,si
  95.            xor eax,eax
  96. del_p1:    mov [es:si],eax
  97.            add si,4
  98.            dec cx
  99.            jnz del_p1
  100.            
  101.            
  102.  
  103.            call get_oldpos         ; Positionen von Seite 2 retten
  104.            
  105.            
  106.           
  107.           ;add [ds:xw],2
  108.           ; add [ds:yw],2
  109.           ; add [ds:zw],2
  110.            
  111.            call rotate_x        
  112.            call rotate_y
  113.            call rotate_z
  114.            
  115.            call transform
  116.            
  117.            mov [ds:color],1        ; Objekt auf Seite 1 darstellen
  118.            mov di,offset _2dpoints
  119.         ;   call draw_obj
  120.            call fill_obj
  121.            
  122.            setpage 000ch           ; Seite 1 an
  123.        
  124.            mov dx,03dah
  125. wb3:       in al,dx
  126.            
  127.            test al,8
  128.            jne wb3
  129. wb4:       in al,dx
  130.            test al,8
  131.            je wb4
  132.  
  133.            mov ax,0a800h
  134.            mov es,ax
  135.            assume es:0a800h
  136.            
  137.            mov dx,03c4h
  138.            mov ax,0f02h
  139.            out dx,ax
  140.  
  141.            mov cx,32000/4
  142.            xor si,si
  143.            xor eax,eax
  144. del_p2:    mov [es:si],eax
  145.            add si,4
  146.            dec cx
  147.            jnz del_p2
  148.            
  149.            call get_oldpos         ; Positionen von Seite 1 retten
  150.            
  151.            add [ds:xw],2        ; Neue Winkel berechnen
  152.            add [ds:yw],4
  153.            add [ds:zw],2
  154.            
  155. warte:     in al,60h            ; Auf 'ESCAPE'-Taste warten
  156.            cmp al,01
  157.            jne main
  158.  
  159.            
  160. exit:      mov ax,0003h
  161.            int 10h
  162.            mov ax,4c00h
  163.            int 21h
  164.  
  165. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  166. ; ROTATIONS-ROUTINE / dreht die 3d-koordinaten in x,y und z-richtung
  167. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  168.  
  169. proc  rotate_x    NEAR
  170.      
  171.      mov   si,offset xpos
  172.      mov   di,offset _3dpoints
  173.      mov   cx,points
  174.  
  175. rotx_it:
  176.      push  cx
  177.      
  178.      mov   ax,[ds:zw]       
  179.      call  cosinus
  180.      imul  [word ds:si]
  181.      mov   cx,dx
  182.      mov   ax,[ds:zw] 
  183.      call  sinus
  184.      imul  [word ds:si+2*points]
  185.      sub   dx,cx
  186.      sal   dx,1
  187.      sal   dx,1
  188.      mov   [ds:di],dx  
  189.  
  190.      mov   ax,[ds:zw]       
  191.      call  sinus
  192.      imul  [word ds:si]
  193.      mov   cx,dx
  194.      mov   ax,[ds:zw] 
  195.      call  cosinus
  196.      imul  [word ds:si+2*points]
  197.      add   dx,cx
  198.      sal   dx,1
  199.      sal   dx,1
  200.      mov   [ds:di+2*points],dx                
  201.       
  202.      pop cx
  203.      add si,2
  204.      add di,2
  205.      dec cx
  206.      jnz rotx_it
  207.      ret
  208.  
  209. endp  rotate_x
  210.  
  211. proc  rotate_y    NEAR
  212.  
  213.      mov cx,points
  214.      mov si,offset xpos
  215.      mov di,offset _3dpoints
  216.  
  217. roty_it:     
  218.      push cx
  219.  
  220.      mov   ax,[ds:yw]       
  221.      call  cosinus
  222.      imul  [word ds:si]
  223.      mov   cx,dx
  224.      mov   ax,[ds:yw] 
  225.      call  sinus
  226.      imul  [word ds:si+4*points]
  227.      sub   dx,cx
  228.      sal   dx,1
  229.      sal   dx,1
  230.      mov   [ds:di],dx  
  231.  
  232.      mov   ax,[ds:yw]       
  233.      call  sinus
  234.      imul  [word ds:si]
  235.      mov   cx,dx
  236.      mov   ax,[ds:yw] 
  237.      call  cosinus
  238.      imul  [word ds:si+4*points]
  239.      add   dx,cx
  240.      sal   dx,1
  241.      sal   dx,1
  242.      mov   [ds:di+4*points],dx                
  243.       
  244.      pop cx
  245.      add si,2
  246.      add di,2
  247.      dec cx
  248.      jnz roty_it
  249.      ret
  250.  
  251. endp  rotate_y
  252.  
  253. proc  rotate_z    NEAR
  254.  
  255.      mov cx,points
  256.      mov si,offset xpos
  257.      mov di,offset _3dpoints
  258.  
  259. rotz_it:
  260.      
  261.      push cx
  262.  
  263.      mov   ax,[ds:xw]       
  264.      call  cosinus
  265.      imul  [word ds:si+2*points]
  266.      mov   cx,dx
  267.      mov   ax,[ds:xw] 
  268.      call  sinus
  269.      imul  [word ds:si+4*points]
  270.      sub   dx,cx
  271.      sal   dx,1
  272.      sal   dx,1
  273.      mov   [ds:di+2*points],dx  
  274.  
  275.      mov   ax,[ds:xw]       
  276.      call  sinus
  277.      imul  [word ds:si+2*points]
  278.      mov   cx,dx
  279.      mov   ax,[ds:xw] 
  280.      call  cosinus
  281.      imul  [word ds:si+4*points]
  282.      add   dx,cx
  283.      sal   dx,1
  284.      sal   dx,1
  285.      mov   [ds:di+4*points],dx                
  286.      
  287.      pop   cx
  288.      add si,2
  289.      add di,2
  290.      dec cx
  291.      jnz rotz_it
  292.      ret
  293.  
  294. endp  rotate_z
  295.  
  296. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  297. ; TRANSFORMATION-ROUTINE / rechnet die 3d-koord. in 2d koord. um
  298. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  299.  
  300. proc  transform     NEAR
  301.      
  302.          mov   cx,points
  303.          mov   di,offset _2dpoints
  304.          mov   si,offset _3dpoints
  305.  
  306. trans_it:mov   bx,[ds:si+4*points] 
  307.          sub   bx,[ds:dist]
  308.      
  309.          mov   ax,[ds:dist]
  310.          imul  [word ds:si]
  311.          idiv  bx            
  312.          sar   ax,1
  313.          sar   ax,1
  314.          sar   ax,1
  315.          sar   ax,1
  316.          add   ax,[ds:x_add]
  317.          mov   [ds:di],ax      
  318.      
  319.          mov   ax,[ds:dist]
  320.          imul  [word ds:si+2*points]
  321.          idiv  bx
  322.          sar   ax,1
  323.          sar   ax,1
  324.          sar   ax,1
  325.          sar   ax,1
  326.          add   ax,[ds:y_add]
  327.          mov   [ds:di+2*points],ax 
  328.      
  329.          add si,2
  330.          add di,2
  331.          dec cx
  332.          jnz trans_it
  333.          ret
  334.  
  335. endp  transform 
  336.  
  337. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  338. ; COSINUS-ROUTINE
  339. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  340.  
  341. proc  cosinus     NEAR
  342.  
  343.      add   ax,64
  344.  
  345.      push  bx
  346.      push  cx
  347.      push  si
  348.      
  349.      mov   bx,ax
  350.      shl   ax,1
  351.      and   ax,0ffh       
  352.      mov   si,offset sinustable
  353.      add   si,ax
  354.      mov   ax,[ds:si]     
  355.      clc
  356.      shl   bl,1         
  357.      jae   cos_pos
  358.      neg   ax            
  359. cos_pos:
  360.      pop   si
  361.      pop   cx
  362.      pop   bx
  363.      ret
  364.  
  365. endp  cosinus
  366.  
  367. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  368. ; SINUS-ROUTINE
  369. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  370.  
  371. proc  sinus    NEAR
  372.  
  373.      push  bx
  374.      push  cx
  375.      push  si
  376.      
  377.      mov   bx,ax
  378.      shl   ax,1
  379.      and   ax,0ffh       
  380.      mov   si,offset sinustable
  381.      add   si,ax
  382.      mov   ax,[ds:si]     
  383.      clc
  384.      shl   bl,1         
  385.      jae   sin_pos
  386.      neg   ax            
  387. sin_pos:
  388.      pop   si
  389.      pop   cx
  390.      pop   bx
  391.      ret
  392.  
  393. endp  sinus
  394.  
  395. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  396. ; DRAWLINE-ROUTINE / zieht eine linie von x1,y1 nach x2,y2 mit farbe col
  397. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  398.  
  399. proc  drawline   NEAR
  400.      
  401.  
  402. draw_it:
  403.      
  404.      push  bp
  405.      mov   ax,[ds:x1]
  406.      mov   bx,[ds:y1]
  407.      push  ax
  408.      push  bx
  409.      mov   bx,4340h
  410.      mov   cx,[ds:x2]
  411.      sub   cx,ax
  412.      jge   deltax_1
  413.      mov   bl,48h
  414.      neg   cx
  415.  
  416. deltax_1:
  417.      
  418.      mov   dx,[ds:y2]
  419.      pop   si
  420.      push  si
  421.      sub   dx,si
  422.      jge   deltay_1
  423.      mov   bh,4bh
  424.      neg   dx
  425.  
  426. deltay_1:
  427.  
  428.      mov   si,offset line_add
  429.      mov   [word cs:si],bx
  430.      cmp   cx,dx
  431.      jge   deltax_2
  432.      mov   bl,90h
  433.      xchg  cx,dx
  434.      jmp   achse3
  435.  
  436. deltax_2:
  437.      
  438.      mov   bh,90h
  439.  
  440. achse3:
  441.      
  442.      mov   si,offset line_sub
  443.      mov   [word cs:si],bx
  444.      shl   dx,1
  445.      mov   bp,dx
  446.      sub   dx,cx
  447.      mov   di,dx
  448.      sub   dx,cx
  449.      pop   bx
  450.      pop   ax
  451.  
  452. line_loop:
  453.      
  454.      push  di
  455.      push  ax
  456.      push  dx
  457.      push  bx
  458.      push  cx
  459.      
  460.      push ax
  461.      mov ax,80
  462.      imul bx
  463.      pop cx
  464.      mov bx,cx
  465.      shr bx,1
  466.      shr bx,1
  467.      add ax,bx
  468.      mov si,ax
  469.  
  470.      and cl,3
  471.      mov ah,1
  472.      shl ah,cl
  473.      mov dx,03c4h
  474.      mov al,02h
  475.      out dx,ax
  476.  
  477.      mov al,[ds:color]
  478.      inc [ds:color]
  479.      mov [es:si],al
  480.      
  481.  
  482.      
  483.      pop   cx
  484.      pop   bx
  485.      pop   dx
  486.      pop   ax
  487.      pop   di
  488.      cmp   di,0
  489.      jge   line_add
  490.  
  491. line_sub:
  492.      
  493.      inc   ax
  494.      inc   bx
  495.      add   di,bp
  496.      loop  line_loop
  497.      jmp   end_line
  498.  
  499. line_add:
  500.      
  501.      inc   ax
  502.      inc   bx
  503.      add   di,dx
  504.      loop  line_loop
  505.  
  506. end_line:
  507.      
  508.      pop     bp
  509.  
  510. stop_line:
  511.      
  512.      ret
  513.  
  514. endp  drawline 
  515.  
  516.  
  517.  
  518. proc  get_oldpos  NEAR
  519.  
  520.          mov cx,2*points
  521.  
  522.          mov si,offset _2dpoints
  523.          mov di,offset old2d
  524.  
  525. old_loop:mov ax,[ds:si]
  526.          mov [ds:di],ax
  527.          add si,2
  528.          add di,2
  529.          dec cx
  530.          jnz old_loop
  531.          
  532.          ret
  533.  
  534. endp  get_oldpos
  535.  
  536. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  537. ; FÜLLROUTINE V1.0
  538. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  539.  
  540. fill_obj  :  mov cx,frames
  541.              mov si,offset xframe
  542.              mov di,offset _2dpoints
  543.              
  544. fill_obj1:   mov bl,[ds:si]
  545.              xor bh,bh
  546.              shl bx,1
  547.  
  548.              mov ax,[ds:di+bx] ;get 1st point of frame
  549.              mov [ds:t_x1],ax
  550.              mov ax,[ds:di+2*points+bx]
  551.              mov [ds:t_y1],ax
  552.  
  553.              inc si
  554.  
  555.              mov bl,[ds:si]
  556.              xor bh,bh
  557.              shl bx,1
  558.  
  559.              mov ax,[ds:di+bx]
  560.              mov [ds:t_x2],ax
  561.              mov ax,[ds:di+2*points+bx]
  562.              mov [ds:t_y2],ax
  563.  
  564.              inc si
  565.  
  566.              mov bl,[ds:si]
  567.              xor bh,bh
  568.              shl bx,1
  569.  
  570.              mov ax,[ds:di+bx]
  571.              mov [ds:t_x3],ax
  572.              mov ax,[ds:di+2*points+bx]
  573.              mov [ds:t_y3],ax
  574.  
  575.              inc si
  576.  
  577.              mov al,[ds:si]
  578.              mov [ds:color],al
  579.  
  580.              inc si
  581.              
  582.              push cx
  583.              push si
  584.              push di
  585.  
  586.              call draw_polygon
  587.  
  588.              pop di
  589.              pop si
  590.              pop cx
  591.  
  592. no_fill:     dec cx
  593.              jnz fill_obj1
  594.  
  595.              ret
  596.  
  597. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  598. ; SET 320*400 Graphics-mode (based on 4 bitplane-splitting) 
  599. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  600.  
  601. proc  set320400  NEAR
  602.  
  603.               mov ax,0013h      
  604.               int 10h
  605.  
  606.               mov dx,03c4h
  607.               mov al,04h
  608.               out dx,al
  609.               inc dx
  610.               in al,dx
  611.               and al,11110111b
  612.               out dx,al
  613.               dec dx
  614.               
  615.               mov ax,0f02h
  616.               out dx,ax
  617.  
  618.               mov dx,03d4h
  619.               mov al,14h
  620.               out dx,al
  621.               inc dx
  622.               in al,dx
  623.               and al,10111111b
  624.               out dx,al
  625.               dec dx
  626.               mov al,17h
  627.               out dx,al
  628.               inc dx
  629.               in al,dx
  630.               or al,01000000b
  631.               out dx,al
  632.  
  633.               mov dx,03d4h
  634.               mov al,09h
  635.               out dx,al
  636.               inc dx
  637.               in al,dx
  638.               and al,01110000b
  639.               out dx,al
  640.               
  641.               mov dx,03c4h
  642.               mov ax,0f02h
  643.               out dx,ax
  644.  
  645.               mov ax,0a000h
  646.               mov es,ax
  647.               assume es:0a000h
  648.               
  649.               mov cx,64000      ; alle bitplanes auf beiden grafikseiten
  650.               xor di,di         ; löschen...
  651.               xor eax,eax
  652.               cld
  653.               rep stosd
  654.  
  655.               ret
  656.  
  657. endp  set320400
  658.  
  659. proc  set640400  NEAR
  660.  
  661.               mov ax,000eh
  662.               int 10h
  663.  
  664.               mov dx,03d4h
  665.               mov al,09h
  666.               out dx,al
  667.               inc dx
  668.               in al,dx
  669.               and al,01111111b
  670.               out dx,al
  671.  
  672.               ret
  673.  
  674. endp  set640400
  675.  
  676. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  677. ; DRAWS A FILLED POLYGON WITH 3 POINTS 
  678. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  679.  
  680. draw_polygon:   mov ax,[ds:t_y1]  ; vergleiche punkt1 mit punkt 2
  681.                 cmp ax,[ds:t_y2]  ; Y von punkt1 kleiner Y von punkt2 ?
  682.                 jbe s_ok_1        ; ja, dann weiter
  683.                                   
  684.                 xchg ax,[ds:t_y2] ; ansonsten X/Y von punkt1 mit X/Y von
  685.                 mov [ds:t_y1],ax  ; punkt2 tauschen
  686.                 mov ax,[ds:t_x1]
  687.                 xchg ax,[ds:t_x2]
  688.                 mov [ds:t_x1],ax
  689.  
  690. s_ok_1:         mov ax,[ds:t_y2]  ; vergleiche punkt2 mit punkt3
  691.                 cmp ax,[ds:t_y3]  ; Y von punkt2 kleiner Y von punkt3 ?
  692.                 jbe s_ok_3        ; ja, dann weiter
  693.                 
  694.                 xchg ax,[ds:t_y3] ; ansonsten X/Y von punkt2 mit X/Y von
  695.                 mov [ds:t_y2],ax  ; punkt3 tauschen
  696.                 mov ax,[ds:t_x3]
  697.                 xchg ax,[ds:t_x2]
  698.                 mov [ds:t_x3],ax
  699.  
  700. s_ok_2:         mov ax,[ds:t_y1]  ; nochmals punkt1 mit neuem punkt2 
  701.                 cmp ax,[ds:t_y2]  ; vergleichen, da wir ja mit punkt3 
  702.                 jbe s_ok_3        ; getauscht haben
  703.                 
  704.                 xchg ax,[ds:t_y2]
  705.                 mov [ds:t_y1],ax
  706.                 mov ax,[ds:t_x1]
  707.                 xchg ax,[ds:t_x2]
  708.                 mov [ds:t_x1],ax
  709.  
  710. s_ok_3:         mov bp,[ds:t_y3]  ; die längste seitenlinie (punkt1-punkt3)
  711.                 mov dx,[ds:t_x3]  ; berechnen
  712.                 mov ax,[ds:t_y1]
  713.                 mov bx,[ds:t_x1]
  714.                 mov di,offset buffer
  715.  
  716.                 call calc_line
  717.  
  718.                 mov bp,[ds:t_y2]  ; nächste seitenlinie berechnen
  719.                 mov dx,[ds:t_x2]  ; von punkt1 nach punkt2
  720.                 mov ax,[ds:t_y1]
  721.                 mov bx,[ds:t_x1]
  722.                 mov di,offset buffer+2
  723.                 
  724.                 call calc_line
  725.  
  726.                 mov bp,[ds:t_y3]  ; und letzte seitenlinie weiter berechnen
  727.                 mov dx,[ds:t_x3]  ; von punkt2 nach punkt3 
  728.                 mov ax,[ds:t_y2]
  729.                 mov bx,[ds:t_x2]
  730.                 
  731.                 call calc_line
  732.                                  ; die seitenlinie von punkt1 nach punkt3
  733.                                  ; hat ebensoviele positionen wie die
  734.                                  ; seitenlinien von punkt1 nach punkt2 und
  735.                                  ; punkt2 nach punkt3 zusammen.
  736.                                  ; was auch nötig ist um später in dieser
  737.                                  ; routine horizontale linien vom punkt einer
  738.                                  ; seitenlinie zur nächsten zu ziehen
  739.  
  740.                 mov bx,01h
  741.                 
  742.                 mov bp,[ds:t_y3]
  743.                 sub bp,[ds:t_y1]
  744.                 inc bp
  745.  
  746.                 mov si,offset buffer
  747.  
  748.                 mov al,bl
  749.  
  750.                 imul dx,[ds:t_y1],ssizex/4
  751.  
  752. draw_nline:     mov di,[si]
  753.                 mov bx,[si+2]
  754.                 sub bx,di
  755.                 jnc width_pos
  756.  
  757.                 add di,bx
  758.                 neg bx
  759.  
  760. width_pos:      inc bx
  761.  
  762.                 push ax
  763.                 push dx
  764.                 call draw_line
  765.                 pop dx
  766.                 pop ax
  767.  
  768.                 add si,4
  769.                 add dx,ssizex/4
  770.                 dec bp
  771.                 jnz draw_nline
  772.  
  773. end_fill:       ret
  774.  
  775.  
  776.  
  777. calc_line:      xor cx,cx      ; CX auf null, wird zur berechnung der
  778.                                ; Steigung benötigt
  779.  
  780.                 sub bp,ax      ; differenz von Y-route berechnen
  781.                 inc bp         ; +1
  782.  
  783.                 sub dx,bx      ; differenz von X-route berechnen
  784.                 jnc dx_not_neg ; wenn X-richtung positiv dann weiter
  785.  
  786.                 mov cx,2       ; ansonsten CX mit 2 laden und DX negieren
  787.                 neg dx
  788.  
  789. dx_not_neg:     inc dx         ; +1
  790.                 mov ax,bx       ; X-beginn in AX laden
  791.  
  792.                 mov bx,1        ; steigungsfaktor berechnen ob positiv oder
  793.                 sub bx,cx       ; negativ (-1/+1)        
  794.  
  795.                 mov cx,bp       ; counter mit Y-differenz laden
  796.  
  797.                 cmp dx,bp       ; vergleiche ob Y-differenz größer X-differenz
  798.                 jbe y_major     ; ja, dann weiter
  799.  
  800.                 mov cx,dx       ; ansonsten counter mit X-differenz laden
  801.                 xchg bp,dx      ; Y-differenz mit X-differenz tauschen
  802.  
  803.                 mov si,bp       ; SI mit X-differenz laden
  804.  
  805. y_next_pixel:   sub si,dx       ; Dump = Dump - dy
  806.                 jnc y_positive
  807.  
  808.                 add si,bp       ; Dump = Dump + dx
  809.  
  810.                 mov [ds:di],ax
  811.                 add di,4
  812.  
  813. y_positive:     add ax,bx ; Add increment
  814.                 dec cx
  815.                 jnz y_next_pixel
  816.  
  817.                 sub ax,bx
  818.                 mov [ds:di],ax
  819.                 add di,4
  820.  
  821.                 jmp end_filled_triangle
  822.  
  823.  
  824.  
  825. y_major:        mov si,bp
  826.  
  827. x_next_pixel:   mov [ds:di],ax
  828.                 add di,4
  829.  
  830.                 sub si,dx ; Dump = Dump - dy
  831.                 jnc x_positive
  832.  
  833.                 add ax,bx ; Add increment
  834.                 add si,bp ; Dump = Dump + dx
  835.  
  836. x_positive:     dec cx
  837.                 jnz x_next_pixel
  838.  
  839. end_filled_triangle:    ret
  840.  
  841.  
  842.  
  843. draw_line:      mov cx,di
  844.                 shr di,2
  845.                 add di,dx
  846.  
  847.                 and cx,3
  848.                 add bx,cx
  849.                                                 
  850.                 mov ch,[ds:color]
  851.                 inc [ds:color]
  852.  
  853.                 mov ax,0f02h
  854.                 shl ah,cl
  855.                 mov dx,03c4h
  856.                 sub bx,4
  857.                 jg not_same_nibble
  858.  
  859.                 neg bl
  860.                 mov cl,bl
  861.                 mov bh,0fh
  862.                 shr bh,cl
  863.                 and ah,bh
  864.                 out dx,ax
  865.                 
  866.                 mov [es:di],ch
  867.                 ret
  868.  
  869.  
  870. not_same_nibble:out dx,ax
  871.                 mov [es:di],ch
  872.                 inc di
  873.  
  874.                 cmp bx,3
  875.                 jle skip_rep
  876.                 
  877.                 mov ax,0f02h
  878.                 out dx,ax
  879.                 mov al,ch
  880.                 mov cx,bx
  881.                 shr cx,2
  882.  
  883.                 rep stosb
  884.  
  885.                 mov ch,al
  886.                 inc ch
  887. skip_rep:       and bx,3
  888.                 jz no_last_byte
  889.  
  890.                 mov cl,bl
  891.                 mov ax,0f002h
  892.                 rol ah,cl
  893.                 out dx,ax
  894.  
  895.                 mov [es:di],ch
  896.  
  897. no_last_byte:   ret              
  898.  
  899.  
  900.  
  901. sort_frames:    mov cx,frames
  902.  
  903.                 mov si,offset frame
  904.                 mov di,offset z_positions
  905.                 mov bp,offset _3dpoints
  906.  
  907. aax:            xor bh,bh
  908.                 mov bl,[ds:si]
  909.                 shl bx,1
  910.  
  911.                 add bx,bp
  912.                 mov ax,[ds:4*points+bx]
  913.  
  914.                 xor bh,bh
  915.                 mov bl,[ds:si+1]
  916.                 shl bx,1
  917.  
  918.                 add bx,bp
  919.                 add ax,[ds:4*points+bx]
  920.  
  921.                 xor bh,bh
  922.                 mov bl,[ds:si+2]
  923.                 shl bx,1
  924.  
  925.                 add bx,bp
  926.                 add ax,[ds:4*points+bx]
  927.  
  928.                 mov [ds:di],ax
  929.  
  930.                 add di,2
  931.                 add si,4
  932.  
  933.                 dec cx
  934.                 jnz aax
  935.  
  936.  
  937.  
  938.  
  939.  
  940. xchange_frames: xor bp,bp
  941.                 mov di,bp
  942.  
  943.                 mov cx,frames
  944.  
  945. aax3:           mov si,bp
  946.  
  947.                 mov [ds:countx],0
  948.  
  949.                 shl si,1
  950.                 mov ax,[ds:z_positions+si]
  951.                 shr si,1
  952.  
  953.                 mov dx,bp
  954.  
  955. aax1:           inc si
  956.  
  957.                 cmp si,cx
  958.                 jae aax2
  959.  
  960.                 shl si,1
  961.                 mov bx,[ds:z_positions+si]
  962.                 shr si,1
  963.                 
  964.                 cmp ax,bx
  965.                 jle aax1
  966.                 
  967.                 inc [ds:countx]
  968.  
  969.                 jmp aax1
  970.                 
  971.                 mov ax,0003h
  972.                 int 10h
  973.                 mov ax,4c00h
  974.                 int 21h
  975.  
  976.  
  977.                 jmp aax1
  978.  
  979. aax2:           mov di,frames
  980.                 mov di,[ds:countx]
  981.                 mov [ds:pots+bp],di
  982.  
  983.                 mov si,dx
  984.  
  985.                 shl di,2
  986.                 
  987.                 shl si,2
  988.                 
  989.                 mov eax,[dword ds:frame+si]
  990.                 mov [dword ds:xframe+di],eax
  991.  
  992.                 inc bp
  993.                 dec cx
  994.                 jnz aax3
  995.  
  996.                 ret
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002. ends  coding
  1003.  
  1004. segment  data1
  1005.  
  1006.  
  1007. color db 0
  1008.  
  1009. countx dw 0
  1010.  
  1011. ssizex                                  equ 320
  1012. ssizey                                  equ 400
  1013.  
  1014. t_x1                    dw 0
  1015. t_y1                    dw 0
  1016. t_x2                    dw 0
  1017. t_y2                    dw 0
  1018. t_x3                    dw 0
  1019. t_y3                    dw 0
  1020.  
  1021. buffer                  dw 1000 dup(0)
  1022.  
  1023. ;
  1024. ; OBJEKT DATEN
  1025. ;
  1026.  
  1027. xpos     dw 500,500,-500
  1028.          dw 500,500,-500
  1029.          
  1030. ypos     dw 500,-500,000
  1031.          dw 500,-500,500
  1032.          
  1033. zpos     dw -500,-500,-500
  1034.          dw 500,500,500
  1035.          
  1036. ;
  1037. ; BINDUNGSLISTE FÜR DIE OBJEKT-PUNKTE
  1038. ;
  1039.  
  1040. lines db 2,0
  1041.       db 2,3
  1042.       db 0,3
  1043.  
  1044. ; FLÄCHENLISTE FÜR FÜLLROUTINE
  1045. ;
  1046. db "ESCAPE"
  1047.  
  1048. frame db 0,1,2,01h
  1049.  
  1050.       db 3,4,5,02h
  1051.  
  1052.       db 255,255,255,255,255,255,255,255
  1053.  
  1054. xframe           db frames*4 dup (0)
  1055.       
  1056.       db 255,255,255,255,255,255,255,255
  1057.  
  1058. z_positions      dw frames dup (0)
  1059.  
  1060.       db 255,255,255,255,255,255,255,255
  1061.  
  1062. pots  dw  10 dup (0)
  1063.  
  1064. ;
  1065. ; DISTANZ VOM AUGE DES BETRACHTERS IN DEN 3D-RAUM
  1066. ;
  1067.  
  1068. dist  dw 2000
  1069.  
  1070. ;
  1071. ; SINUSTABELLE MIT 128 WERTEN
  1072. ;
  1073.  
  1074. sinustable dw 0000h,0192h,0324h,04b5h,0646h
  1075.            dw 07d6h,0964h,0af1h,0c7ch,0e06h,0f8dh
  1076.            dw 1112h,1294h,1413h,1590h,1709h,187eh
  1077.            dw 19efh,1b5dh,1cc6h,1e2bh,1f8ch,20e7h
  1078.            dw 223dh,238eh,24dah,2620h,2760h,289ah
  1079.            dw 29ceh,2afbh,2c21h,2d41h,2e5ah,2f6ch
  1080.            dw 3076h,3179h,3274h,3368h,3453h,3537h
  1081.            dw 3612h,36e5h,37b0h,3871h,392bh,39dbh
  1082.            dw 3a82h,3b21h,3bb6h,3c42h,3cc5h,3d3fh
  1083.            dw 3dafh,3e15h,3e72h,3ec5h,3f0fh,3f4fh
  1084.            dw 3f85h,3fb1h,3fd4h,3fech,3ffbh,4000h
  1085.            dw 3ffbh,3fech,3fd4h,3fb1h,3f85h,3f4fh
  1086.            dw 3f0fh,3ec5h,3e72h,3e15h,3dafh,3d3fh
  1087.            dw 3cc5h,3c42h,3bb6h,3b21h,3a82h,39dbh
  1088.            dw 392bh,3871h,37b0h,36e5h,3612h,3537h
  1089.            dw 3453h,3368h,3274h,3179h,3076h,2f6ch
  1090.            dw 2e5ah,2d41h,2c21h,2afbh,29ceh,289ah
  1091.            dw 2760h,2620h,24dah,238eh,223dh,20e7h
  1092.            dw 1f8ch,1e2bh,1cc6h,1b5dh,19efh,187eh
  1093.            dw 1709h,1590h,1413h,1294h,1112h,0f8dh
  1094.            dw 0e06h,0c7ch,0af1h,0964h,07d6h,0646h
  1095.            dw 04b5h,0324h,0192h
  1096.   
  1097. ;
  1098. ; LINIEN-PUNKTE FÜR draw_obj-ROUTINE
  1099. ;
  1100.  
  1101. x1      dw 0
  1102. x2      dw 0
  1103. y1      dw 0
  1104. y2      dw 0
  1105.  
  1106. ;
  1107. ; ECK-PUNKTE FÜR fill_frame-ROUTINE
  1108. ;
  1109.  
  1110. xf1     dw 0
  1111. xf2     dw 0
  1112. yf1     dw 0
  1113. yf2     dw 0
  1114.  
  1115. ;
  1116. ; WINKEL FÜR DIE DREHUNGEN IN X,Y UND Z-RICHTUNG
  1117. ;
  1118.  
  1119. xw      dw 0     
  1120. yw      dw 0
  1121. zw      dw 0
  1122.  
  1123. ;
  1124. ; PUNKTE FÜR FÜLLROUTINE
  1125. ;
  1126.  
  1127. f_x1    dw 0
  1128. f_y1    dw 0
  1129. f_x2    dw 0
  1130. f_y2    dw 0
  1131. f_x3    dw 0
  1132. f_y3    dw 0
  1133.  
  1134. ;
  1135. ; PUFFER FÜR ROTIERTE 3D-KOORDINATEN
  1136. ;
  1137.  
  1138. _3dpoints    dw 3*points DUP (1) ; gedrehte Koord.
  1139.  
  1140. ;
  1141. ; PUFFER FÜR UMGERECHNETE 2D-KOORDINATEN
  1142. ;
  1143.  
  1144. _2dpoints   dw 2*points DUP (1) ; 2D-Koordinaten
  1145.      
  1146. ;
  1147. ; PUFFER FÜR ALTE 2D-KOORDINATEN
  1148. ;
  1149.  
  1150. old2d       dw 2*points dup (0) ; Alte 2D-Koordinaten
  1151.  
  1152. ;
  1153. ; PUFFER FÜR FÜLLKOORDINATEN
  1154. ;
  1155.  
  1156. buffer_pos    dw 0
  1157. buffer_count  dw 0
  1158.  
  1159. fill_buf      dw 1000 dup (?)
  1160.  
  1161.  
  1162. ;
  1163. ; 2D-POINTER FÜR POSITIONIERUNG AUF BILDSCHIRM
  1164. ;
  1165.  
  1166. x_add    dw 160
  1167. y_add    dw 100
  1168.  
  1169. ;
  1170. ; FARBDATEN FÜR DIE GLASFLÄCHEN
  1171. ;
  1172.  
  1173. colorpal db 00,00,00
  1174.          db 00,00,50
  1175.          db 00,00,50
  1176.          db 00,00,40
  1177.  
  1178.  
  1179. ends  data1
  1180.  
  1181. end start
  1182.  
  1183.      mov   ax,[ds:x1]
  1184.      cmp   ax,[ds:x2]
  1185.      jz    no_xadd
  1186.      jmp   draw_it
  1187.  
  1188. no_xadd:
  1189.      
  1190.      mov   ax,[ds:y1]
  1191.      cmp   ax,[ds:y2]
  1192.      jnz   draw_it
  1193.      
  1194.      mov ax,[ds:x1]
  1195.      mov bx,[ds:y1]
  1196.      jmp   stop_line
  1197.